

const path = require('path');
const os = require('os');

function createShortcut() {
    if (os.platform() === 'win32') {
        const appPath = path.join(process.execPath);
        const startupFolder = path.join(process.env.APPDATA, 'Microsoft\\Windows\\Start Menu\\Programs\\Startup');
        const shortcutPath = path.join(startupFolder, 'pi-moint.lnk');
        // 使用Windows的命令行工具创建快捷方式
        const cmd = `powershell "$s=(New-Object -COM WScript.Shell).CreateShortcut('${shortcutPath}'); $s.TargetPath='${appPath}'; $s.Save()"`;
        try {
            require('child_process').execSync(cmd);
        } catch (error) {
            console.error('Failed to create startup shortcut on Windows:', error);
        }
    } else if (os.platform() === 'darwin') {
        const appPath = path.join(process.execPath);
        const script = `tell application "System Events" to make login item at end with properties {path:"${appPath}", hidden:false}`;
        try {
            require('child_process').execSync(`osascript -e '${script}'`);
        } catch (error) {
            console.error('Failed to create startup item on macOS:', error);
        }
    }
}

export default createShortcut
